本文整理汇总了C#中ICmObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ICmObject.GetType方法的具体用法?C# ICmObject.GetType怎么用?C# ICmObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICmObject
的用法示例。
在下文中一共展示了ICmObject.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassPropertySelector
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="ClassPropertySelector"/> class.
/// </summary>
/// ------------------------------------------------------------------------------------
public ClassPropertySelector(ICmObject obj) : this()
{
if (obj == null)
return;
foreach (FDOClass cls in cboClass.Items)
{
if (obj.GetType() == cls.ClassType)
{
cboClass.SelectedItem = cls;
cboClass_SelectionChangeCommitted(null, null);
}
}
}
示例2: InitializeConcordanceSearch
private bool InitializeConcordanceSearch(ICmObject cmo, ITsString tssObj)
{
string sType = cmo.GetType().Name;
string sTag = m_mediator.StringTbl.GetString(sType, "ClassNames");
SetDefaultVisibilityOfItems(false, sTag);
m_fObjectConcorded = true;
m_hvoMatch = cmo.Hvo;
m_backupHvo = cmo.Owner == null ? 0 : cmo.Owner.Hvo;
ITsTextProps ttpObj = tssObj.get_PropertiesAt(0);
int nVar;
int ws = ttpObj.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar);
m_fwtbItem.WritingSystemCode = (ws > 0) ? ws : m_cache.DefaultVernWs;
int dyHeight = m_fwtbItem.PreferredHeight;
m_fwtbItem.Height = dyHeight;
m_fwtbItem.Tss = tssObj;
int dxWidth = m_fwtbItem.PreferredWidth;
m_fwtbItem.Width = dxWidth;
LoadMatches(true);
return true;
}
示例3: GetProperty
/// --------------------------------------------------------------------------------
/// <summary>
/// Gets the property.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="property">The property.</param>
/// <returns></returns>
/// --------------------------------------------------------------------------------
protected object GetProperty(ICmObject target, string property)
{
Type type = target.GetType();
System.Reflection.PropertyInfo info = type.GetProperty(property,
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.FlattenHierarchy );
if (info == null)
throw new ArgumentException("There is no public property named '"
+ property + "' in " + type.ToString()
+ ". Remember, properties often end in a multi-character suffix such as OA, OS, RA, RS, or Accessor.");
return info.GetValue(target,null);
}
示例4: IsPropertyDisplayed
/// ------------------------------------------------------------------------------------
/// <summary>
/// Determines whether or not the specified property name of the specified object
/// should be displayed.
/// </summary>
/// ------------------------------------------------------------------------------------
public static bool IsPropertyDisplayed(ICmObject cmObj, string propName)
{
if (s_showCmObjProps || !IsCmObjectProperty(propName))
{
FDOClass cls;
if (s_FDOClassesByType.TryGetValue(cmObj.GetType(), out cls))
return cls.IsPropertyDisplayed(propName);
}
return false;
}
示例5: GetProperty
protected object GetProperty(ICmObject target, string property)
{
if (target == null)
return null;
var fWantHvo = false;
var type = target.GetType();
var info = type.GetProperty(property, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
if (info == null && property.EndsWith(".Hvo"))
{
fWantHvo = true;
var realprop = property.Substring(0, property.Length - 4);
info = type.GetProperty(realprop, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
}
if (info == null)
throw new ConfigurationException("There is no public property named '" + property + "' in " + type + ". Remember, properties often end in a two-character suffix such as OA,OS,RA, or RS.");
object result;
try
{
result = info.GetValue(target, null);
if (fWantHvo)
{
var hvo = 0;
if (result != null)
hvo = ((ICmObject)result).Hvo;
return hvo > 0 ? hvo.ToString() : "0";
}
}
catch (Exception error)
{
throw new ApplicationException(String.Format("There was an error while trying to get the property {0}. One thing that has caused this in the past has been a database which was not migrated properly.", property), error);
}
return result;
}
示例6: CallSortMethod
/// <summary>
/// Calls the sort method.
/// </summary>
/// <param name="cmo">The object.</param>
/// <param name="sortedFromEnd">if set to <c>true</c> [sorted from end].</param>
/// <returns></returns>
private string CallSortMethod(ICmObject cmo, bool sortedFromEnd)
{
Type typeCmo = cmo.GetType();
try
{
MethodInfo mi = typeCmo.GetMethod(m_sMethodName);
if (mi == null)
return null;
object obj;
if (mi.GetParameters().Length == 2)
{
// Enhance JohnT: possibly we should seek to evaluate this every time, in case it is a magic WS like
// "best vernacular". But interpreting those requires a flid, and we don't have one; indeed, the
// method may retrieve information from several. So we may as well just accept that the fancy ones
// won't work.
if (m_ws == 0 && WritingSystemName != null)
m_ws = LangProject.InterpretWsLabel(cmo.Cache, WritingSystemName, 0, 0, 0, null);
obj = mi.Invoke(cmo, new object[] { sortedFromEnd, m_ws });
}
else
{
obj = mi.Invoke(cmo, new object[] { sortedFromEnd });
}
return (string)obj;
}
catch (Exception)
{
return null;
}
}
示例7: GetStringValueForTest
private string GetStringValueForTest(ICmObject currentObject, XmlNode node)
{
int hvo = 0;
int flid = GetFlidAndHvo(currentObject, node, ref hvo);
if (flid == 0 || hvo == 0)
{
// Try for a property on the object.
string sField = XmlUtils.GetOptionalAttributeValue(node, "field");
if (String.IsNullOrEmpty(sField))
return null;
try
{
Type type = currentObject.GetType();
PropertyInfo info = type.GetProperty(sField,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
if (info != null)
{
object result = info.GetValue(currentObject, null);
return result.ToString();
}
}
catch (Exception error)
{
throw new ApplicationException(string.Format("There was an error while trying to get the property {0}. One thing that has caused this in the past has been a database which was not migrated properly.", sField), error);
}
return null; // This is rather arbitrary...objects missing, what should each test do?
}
switch ((CellarPropertyType)m_mdc.GetFieldType(flid))
{
case CellarPropertyType.Unicode:
return currentObject.Cache.DomainDataByFlid.get_UnicodeProp(hvo, flid);
case CellarPropertyType.String:
return currentObject.Cache.DomainDataByFlid.get_StringProp(hvo, flid).Text;
case CellarPropertyType.MultiUnicode:
return currentObject.Cache.DomainDataByFlid.get_MultiStringAlt(hvo, flid,
GetSingleWritingSystemDescriptor(node)).Text;
case CellarPropertyType.MultiString:
return currentObject.Cache.DomainDataByFlid.get_MultiStringAlt(hvo, flid,
GetSingleWritingSystemDescriptor(node)).Text;
default:
return null;
}
}
示例8: MergeObject
/// ------------------------------------------------------------------------------------
/// <summary>
/// Merges object into this object.
/// if fLoseNoStringData is false:
/// For atomic properties, if this object has something in the property, the source
/// property is ignored. For sequence properties, the objects in the source will be
/// moved and appended to the properties in this object. Any references to the
/// source object will be transferred to this object. The source object is deleted
/// at the end of this method (objSrc.DeleteUnderlyingObject() call).
/// String properties are copied from the source if the destination (this) has no value
/// and the source has a value.
///
/// if fLoseNoStringData is true, the above is modified as follows:
/// 1. If a string property has a value in both source and destination, and the values
/// are different, append the source onto the destination.
/// 2. If an atomic object property has a value in both source and destination,
/// recursively merge the value in the source with the value in the destination.
/// </summary>
/// <param name="objSrc">Object whose properties will be merged into this object's properties</param>
/// <remarks>
/// NB: The given object will be deleted in this method, so don't expect it to be valid, afterwards.
/// </remarks>
/// <param name="fLoseNoStringData"></param>
/// ------------------------------------------------------------------------------------
public virtual void MergeObject(ICmObject objSrc, bool fLoseNoStringData)
{
Debug.Assert(m_cache != null);
// We don't allow merging items of different classes.
Debug.Assert(ClassID == objSrc.ClassID);
if (ClassID != objSrc.ClassID)
return;
IFwMetaDataCache mdc = m_cache.MetaDataCacheAccessor;
PropertyInfo[] myProperties = GetType().GetProperties();
PropertyInfo[] srcProperties = objSrc.GetType().GetProperties();
string fieldname;
// Process all the fields in the source.
foreach(uint flid in DbOps.GetFieldsInClassOfType(mdc, ClassID, FieldType.kgrfcptAll))
{
/* These values will also be returned because they are for most of CmObject's flids.
* I think it will do this for each superclass, so there could be some repeats on them.
*
* pvuFields->Push(101); // kflidCmObject_Guid
* pvuFields->Push(102); // kflidCmObject_Class
* pvuFields->Push(103); // kflidCmObject_Owner
* pvuFields->Push(104); // kflidCmObject_OwnFlid
* pvuFields->Push(105); // kflidCmObject_OwnOrd
* //pvuFields->Push(106); // kflidCmObject_UpdStmp
* //pvuFields->Push(107); // kflidCmObject_UpdDttm
*
*/
if (flid < 1000)
continue; // Do nothing for the CmObject flids.
if (flid >= (int)SpecialTagValues.ktagMinVp)
continue; // Do nothing for virtual properties.
int nType = mdc.GetFieldType(flid);
fieldname = mdc.GetFieldName(flid);
//|| fieldname == "DateModified"
//|| nType == (int)FieldType.kcptTime // This is handled by a separate connection, so it can time out, if another transaction is open.
if (fieldname == "DateCreated"
|| nType == (int)FieldType.kcptImage // FDO does not support this one.
|| nType == (int)FieldType.kcptGenDate) // FDO does not support setter for gendate.
continue; // Don't mess with this one.
// Set suffixes on some of the types.
switch (nType)
{
case (int)FieldType.kcptOwningAtom: // 23
{
fieldname += "OA";
break;
}
case (int)FieldType.kcptReferenceAtom: // 24
{
fieldname += "RA";
break;
}
case (int)FieldType.kcptOwningCollection: // 25
{
fieldname += "OC";
break;
}
case (int)FieldType.kcptReferenceCollection: // 26
{
fieldname += "RC";
break;
}
case (int)FieldType.kcptOwningSequence: // 27
{
fieldname += "OS";
break;
}
case (int)FieldType.kcptReferenceSequence: // 28
{
fieldname += "RS";
break;
}
}
Object myCurrentValue = null;
//.........这里部分代码省略.........
示例9: GetMethodResult
protected object GetMethodResult(ICmObject target, string methodName, object[] args)
{
Type type = target.GetType();
MethodInfo mi = type.GetMethod(methodName);
if (mi == null)
throw new ConfigurationException ("There is no public method named '" + methodName + ".");
object result = null;
try
{
result = mi.Invoke(target, args);
}
catch (Exception error)
{
throw new ApplicationException (string.Format("There was an error while executing the method {0}.", methodName), error);
}
return result;
}
示例10: DumpObject
protected void DumpObject(TextWriter contentsStream, ICmObject currentObject, string sClassTag)
{
string className = currentObject.ClassName;
XmlNode classNode = null;
if (sClassTag != null && sClassTag.Length > 0)
{
className = className + "-" + sClassTag;
classNode = GetClassTemplateNode(className);
}
if (classNode == null)
{
classNode = FindClassTemplateNode(currentObject.GetType(), sClassTag);
}
if (classNode == null)
{
return; // would have thrown an exception if that's what the template wanted
}
if (m_filters != null)
{
foreach (IFilterStrategy filter in m_filters)
{
string explanation;
if (!filter.DoInclude(currentObject, out explanation))
{
if (explanation == null)
explanation = "none";
using (var writer = XmlWriter.Create(contentsStream, new XmlWriterSettings { OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Fragment }))
{
writer.WriteComment(String.Format(" Object filtered out by filter {0}, reason: {1} ", filter.Label, explanation));
// would choke the parser later if there were reserved chars in there
//contentsStream.Write("<!-- Object filtered out by filter " + filter.Label + ", reason: "+ explanation + " ");
// contentsStream.Write(" -->");
}
return;
}
}
}
DoChildren(/*null,*/ contentsStream, currentObject, classNode, null);
}
示例11: GetProperty
protected object GetProperty(ICmObject target, string property)
{
if (target == null)
{
return null;
}
if (property == "Hvo")
{
return GetIdString(target.Hvo);
}
else if (property == "Guid")
{
return (target.Guid.ToString());
}
else if (property == "Owner")
{
return target.Owner;
}
else if (property == "IndexInOwner")
{
return target.IndexInOwner.ToString();
}
else if (IsCustomField(target, property))
{
return GetCustomFieldValue(target, property);
}
Type type = target.GetType();
PropertyInfo info = type.GetProperty(property, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
bool fWantHvo = false;
if (info == null && property.EndsWith(".Hvo"))
{
fWantHvo = true;
string realprop = property.Substring(0, property.Length - 4);
info = type.GetProperty(realprop, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
}
if (info == null)
{
throw new ConfigurationException("There is no public property named '" + property + "' in " + type.ToString() + ". Remember, properties often end in a two-character suffix such as OA,OS,RA, or RS.");
}
object result = null;
try
{
result = info.GetValue(target,null);
if (fWantHvo)
{
int hvo = 0;
if (result != null)
hvo = ((ICmObject)result).Hvo;
return hvo > 0 ? GetIdString(hvo) : "0";
}
}
catch (Exception error)
{
throw new ApplicationException (string.Format("There was an error while trying to get the property {0}. One thing that has caused this in the past has been a database which was not migrated properly.", property), error);
}
return result;
}
示例12: DoReferenceVectorElement
/// <summary>
/// The <refVector> element is used when you just want to make a list of
/// references to other elements that will be in the output file.
/// </summary>
/// <param name="contentsStream"></param>
/// <param name="currentObject"></param>
/// <param name="node"></param>
protected void DoReferenceVectorElement(TextWriter contentsStream,
ICmObject currentObject, XmlNode node)
{
bool ordered = XmlUtils.GetBooleanAttributeValue(node, "ordered");
string label = XmlUtils.GetOptionalAttributeValue(node, "itemLabel");
if (label == null)
label ="object";
string field = XmlUtils.GetManditoryAttributeValue(node, "field");
bool fXmlVirtual = XmlUtils.GetOptionalBooleanAttributeValue(node, "virtual", false);
bool fWriteAsRelation = XmlUtils.GetOptionalBooleanAttributeValue(node, "writeAsRelation", false);
//Debug.WriteLine ("<refVector field ="+field+">");
int flid = GetFieldId2(currentObject.ClassID, field, true);
if (m_mapFlids.ContainsKey(flid))
flid = m_mapFlids[flid];
int[] hvos;
if (flid <= 0)
{
if (fXmlVirtual)
{
hvos = LoadVirtualField(currentObject, field);
}
else
{
throw new ConfigurationException ("There is no field named '" + field + "' in "+currentObject.GetType().ToString()+". Remember that fields are the actual CELLAR names, so they do not have FDO suffixes like OA or RS.");
}
}
else
{
int chvo = m_cache.DomainDataByFlid.get_VecSize(currentObject.Hvo, flid);
using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative<int>(chvo))
{
m_cache.DomainDataByFlid.VecProp(currentObject.Hvo, flid, chvo, out chvo, arrayPtr);
hvos = MarshalEx.NativeToArray<int>(arrayPtr, chvo);
}
}
string property = XmlUtils.GetOptionalAttributeValue(node, "itemProperty");
if (property == null)
property = "ShortName";
string wsProp = XmlUtils.GetOptionalAttributeValue(node, "itemWsProp");
if (m_format == "xml")
{
int index = 0;
bool fInternalTraits = XmlUtils.GetOptionalBooleanAttributeValue(node, "internalTraits", false);
string sFieldMemberOf = XmlUtils.GetOptionalAttributeValue(node, "fieldMemberOf");
string sFieldMemberOfTrait = XmlUtils.GetOptionalAttributeValue(node, "fieldMemberOfTrait");
int flidMemberOf = 0;
if (!String.IsNullOrEmpty(sFieldMemberOf) && !String.IsNullOrEmpty(sFieldMemberOfTrait))
{
flidMemberOf = GetFieldId2(currentObject.ClassID, sFieldMemberOf, true);
}
foreach (int hvo in hvos)
{
if (fWriteAsRelation)
{
string labelWs;
string s;
if (GetRefPropertyData(property, wsProp, hvo, out labelWs, out s))
{
if (ordered && hvos.Length > 1)
{
contentsStream.Write("<relation type=\"{0}\" ref=\"{1}\" order=\"{2}\">",
XmlUtils.MakeSafeXmlAttribute(label), XmlUtils.MakeSafeXmlAttribute(s), index);
++index;
}
else
{
contentsStream.Write("<relation type=\"{0}\" ref=\"{1}\">",
XmlUtils.MakeSafeXmlAttribute(label), XmlUtils.MakeSafeXmlAttribute(s));
}
if (fInternalTraits)
{
if (!ordered || index <= 1)
{
contentsStream.WriteLine();
DoChildren(contentsStream, currentObject, node, String.Empty);
}
if (flidMemberOf != 0)
{
int[] rghvoT = ((ISilDataAccessManaged)m_cache.DomainDataByFlid).VecProp(currentObject.Hvo, flidMemberOf);
for (int i = 0; i < rghvoT.Length; ++i)
{
if (rghvoT[i] == hvo)
{
if (ordered && index > 1)
contentsStream.WriteLine();
contentsStream.WriteLine("<trait name=\"{0}\" value=\"true\"/>",
XmlUtils.MakeSafeXmlAttribute(sFieldMemberOfTrait));
break;
}
}
}
}
//.........这里部分代码省略.........
示例13: DoReferenceObjVectorElement
/// <summary>
/// The <refObjVector> element is used when you want to expand the referenced
/// objects as subparts of the same element in the output file.
/// </summary>
/// <param name="contentsStream"></param>
/// <param name="currentObject"></param>
/// <param name="node"></param>
protected void DoReferenceObjVectorElement(TextWriter contentsStream,
ICmObject currentObject, XmlNode node)
{
if (m_format != "sf")
throw new ConfigurationException("<refObjVector> is supported only for standard format output.");
string label = XmlUtils.GetOptionalAttributeValue(node, "itemLabel");
if (label == null)
label = "subobject";
string field = XmlUtils.GetManditoryAttributeValue(node, "field");
string sVirtual = XmlUtils.GetOptionalAttributeValue(node, "virtual");
bool fVirtual = false;
if (sVirtual != null)
{
sVirtual = sVirtual.ToLower();
if (sVirtual == "true" || sVirtual == "t" || sVirtual == "yes" || sVirtual == "y")
fVirtual = true;
}
int flid = GetFieldId2(currentObject.ClassID, field, true);
int[] hvos;
if (flid <= 0)
{
if (fVirtual)
{
hvos = LoadVirtualField(currentObject, field);
}
else
{
throw new ConfigurationException("There is no field named '" + field + "' in " +
currentObject.GetType().ToString() +
". Remember that fields are the actual CELLAR names, so they do not have FDO suffixes like OA or RS.");
}
}
else
{
if (m_mapFlids.ContainsKey(flid))
flid = m_mapFlids[flid];
int chvo = m_cache.DomainDataByFlid.get_VecSize(currentObject.Hvo, flid);
using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative<int>(chvo))
{
m_cache.DomainDataByFlid.VecProp(currentObject.Hvo, flid, chvo, out chvo, arrayPtr);
hvos = MarshalEx.NativeToArray<int>(arrayPtr, chvo);
}
}
string property = XmlUtils.GetOptionalAttributeValue(node, "itemProperty");
if (property == null)
property = "ShortName";
string wsProp = XmlUtils.GetOptionalAttributeValue(node, "itemWsProp");
string sClassTag = XmlUtils.GetOptionalAttributeValue(node, "classtag");
string labelWs = "";
ILgWritingSystemFactory wsf = m_cache.WritingSystemFactory;
foreach (int hvo in hvos)
{
var co = m_cmObjectRepository.GetObject(hvo);
if (String.IsNullOrEmpty(label) || String.IsNullOrEmpty(property))
{
contentsStream.WriteLine();
}
else
{
object obj = GetProperty(co, property);
if (obj == null)
continue;
string s = Icu.Normalize(obj.ToString(), m_eIcuNormalizationMode);
string separator = "";
if (wsProp != null)
{
obj = GetProperty(co, wsProp);
if (obj != null)
{
IWritingSystem ws = obj as IWritingSystem ?? m_wsManager.Get((string)obj);
if (ws != null)
labelWs = LabelString(ws);
}
}
if (!String.IsNullOrEmpty(labelWs))
separator = "_";
string sTmp = String.Format("{4}\\{0}{1}{2} {3}", label, separator, labelWs, s, Environment.NewLine);
contentsStream.Write(sTmp);
}
DumpObject(contentsStream, co, sClassTag);
}
}
示例14: GetFieldsFromMetaDataCache
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets the fields from meta data cache.
/// </summary>
/// ------------------------------------------------------------------------------------
private PropertyInfo[] GetFieldsFromMetaDataCache(ICmObject cmObj)
{
List<PropertyInfo> props = new List<PropertyInfo>();
if (cmObj != null)
{
int[] flids = m_mdc.GetFields(cmObj.ClassID, true, (int)CellarPropertyTypeFilter.All);
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty;
// Get only the fields for the object that are specified in the meta data cache.
foreach (int flid in flids)
{
string fieldName = m_mdc.GetFieldName(flid);
CellarPropertyType fieldType = (CellarPropertyType)m_mdc.GetFieldType(flid);
string suffix;
if (m_fldSuffix.TryGetValue(fieldType, out suffix))
fieldName += suffix;
PropertyInfo pi = cmObj.GetType().GetProperty(fieldName, flags);
if (pi != null)
props.Add(pi);
}
}
return (props.Count > 0 ? props.ToArray() : base.GetPropsForObj(cmObj));
}
示例15: GetObjectForTest
private object GetObjectForTest(ICmObject currentObject, XmlNode node)
{
int hvo = 0;
int flid = GetFlidAndHvo(currentObject, node, ref hvo);
if (flid == 0 || hvo == 0)
{
string sField = XmlUtils.GetOptionalAttributeValue(node, "field");
if (String.IsNullOrEmpty(sField))
return null; // This is rather arbitrary...objects missing, what should each test do?
try
{
Type type = currentObject.GetType();
PropertyInfo info = type.GetProperty(sField,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
if (info != null)
{
object result = info.GetValue(currentObject, null);
return result;
}
}
catch (Exception error)
{
throw new ApplicationException(string.Format("There was an error while trying to get the property {0}. One thing that has caused this in the past has been a database which was not migrated properly.", sField), error);
}
return null; // This is rather arbitrary...objects missing, what should each test do?
}
switch ((CellarPropertyType)m_mdc.GetFieldType(flid))
{
case CellarPropertyType.OwningAtomic:
case CellarPropertyType.ReferenceAtomic:
int hvoT = currentObject.Cache.DomainDataByFlid.get_ObjectProp(hvo, flid);
if (hvoT == 0)
return null;
else
return String.Empty; // it's not null, which is all that matters for the test!
default:
return null;
}
}