本文整理汇总了C#中IDataObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IDataObject.GetType方法的具体用法?C# IDataObject.GetType怎么用?C# IDataObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataObject
的用法示例。
在下文中一共展示了IDataObject.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckRequiredProperties
private static void CheckRequiredProperties(IDataObject dataObj, ref DataObjectOperationResult result)
{
//Get Required Properties
var requiredProperties = dataObj.GetType()
.GetProperties()
.Where(x => Attribute.IsDefined(x, typeof(RequiredValueAttribute)));
//Check to Ensure Required Properties are not Null or empty
foreach (var reqProp in requiredProperties)
{
var prop = dataObj.GetType().GetProperty(reqProp.Name);
var propValue = prop.GetValue(dataObj, null);
bool isNull = false;
switch (prop.PropertyType.Name.ToLower())
{
case "string":
isNull = string.IsNullOrEmpty((string)propValue);
break;
default:
isNull = propValue == null;
break;
}
if (isNull)
{
RequiredValueAttribute reqAttrib = (RequiredValueAttribute)(prop.GetCustomAttributes(typeof(RequiredValueAttribute), false)[0]);
//var reqAttrib = prop.GetCustomAttribute<RequiredValueAttribute>();
result.Message = "A Required Value is Missing";
result.ErrorMessages.Add(reqProp.Name, reqAttrib.ErrorMessage);
result.Success = false;
}
}
}
示例2: FixupFloatingObjectsToString
/// <summary>
/// Since floating objects might have no valid/useful ToString() result yet, prefix them with the typename and id.
/// </summary>
/// <param name="obj">The current object</param>
/// <param name="e">The ToString MethodReturnEventArgs.</param>
internal static void FixupFloatingObjectsToString(IDataObject obj, MethodReturnEventArgs<string> e)
{
if (obj.Context != null && obj.Context.IsReadonly) return;
if (Helper.IsFloatingObject(obj))
{
e.Result = String.Format("new {0}(#{1}): {2}", obj.GetType().Name, obj.ID, e.Result);
}
}
示例3: Check
/// <summary>
/// Manufacture and check object ACL against the current session context.
/// </summary>
/// <param name="instance"></param>
/// <param name="op"></param>
public static void Check(IDataObject instance, DataOperation op)
{
// create an instance of an ACL
string aclClassTypeName = string.Format("Vestris.Service.Data.{0}ClassACL", instance.GetType().Name);
Type aclClassType = Assembly.GetExecutingAssembly().GetType(aclClassTypeName, true, false);
object[] args = { instance };
ACL acl = (ACL)Activator.CreateInstance(aclClassType, args);
acl.Check((UserContext) SessionManager.CurrentSessionContext, op);
}
示例4: CheckEMailProperties
private static void CheckEMailProperties(IDataObject dataObj, ref DataObjectOperationResult result)
{
//Get E-Mail Properties
var emailProperties = dataObj.GetType().GetProperties()
.Where(x => Attribute.IsDefined(x, typeof(EmailAttribute)));
//Check to Ensure Required Properties are Valid E-Mail Addresses
foreach (var emlProp in emailProperties)
{
var prop = dataObj.GetType().GetProperty(emlProp.Name);
var propValue = prop.GetValue(dataObj);
var emlAttrib = prop.GetCustomAttribute<EmailAttribute>();
if (emlAttrib.IsValid(propValue) != true)
{
result.Message = "An Error Occured While Validating Input";
result.ErrorMessages.Add(emlProp.Name, "Not A Valid E-Mail Address");
result.Success = false;
}
}
}
示例5: DataObjectRelationship
public DataObjectRelationship(IDataObject dataObjectA, IDataObject dataObjectB)
{
this.DataObjects = new List<DataObjectRelationshipEntry>();
this.DataObjects.Add(new DataObjectRelationshipEntry
{
DataObjectId = dataObjectA.Id,
DataObjectType = dataObjectA.GetType()
});
this.DataObjects.Add(new DataObjectRelationshipEntry
{
DataObjectId = dataObjectB.Id,
DataObjectType = dataObjectB.GetType()
});
}
示例6: UpdateValues
/// <summary>
/// Set the values of this object to the values of the dummy object, if the dummys value is non-null.
/// </summary>
/// <param name="dummy">
/// The dummy object, representing new values.
/// </param>
public void UpdateValues(IDataObject dummy)
{
Contract.Requires(dummy != null); // Re-stipulate this contract, since it must be checked before the added contracts.
Contract.Requires(dummy.GetType() == this.GetType());
Contract.Requires(dummy.PrimaryKey == null || (((VoterDO)dummy).PrimaryKey >= 101000001 && ((VoterDO)dummy).PrimaryKey <= 3012999999));
VoterDO voterDummy = dummy as VoterDO;
Contract.Assert(voterDummy != null);
this.PollingStationId = voterDummy.PollingStationId ?? this.PollingStationId;
this.PrimaryKey = voterDummy.PrimaryKey ?? this.PrimaryKey;
this.Name = voterDummy.Name ?? this.Name;
this.City = voterDummy.City ?? this.City;
this.Address = voterDummy.Address ?? this.Address;
this.CardPrinted = voterDummy.CardPrinted ?? this.CardPrinted;
this.Voted = voterDummy.Voted ?? this.Voted;
}
示例7: GetRelatedObjects
public override IList<IDataObject> GetRelatedObjects(IDataObject dataObject, string relatedObjectType, int pageSize, int startIndex)
{
string objectType = dataObject.GetType().Name;
IList<IDataObject> dataObjects = null;
if (objectType == typeof(GenericDataObject).Name)
{
objectType = ((GenericDataObject)dataObject).ObjectType;
}
try
{
DataObject parentDataObject = _dataDictionary.dataObjects.Find(x => x.objectName.ToUpper() == objectType.ToUpper());
if (parentDataObject == null)
throw new Exception("Parent data object [" + objectType + "] not found.");
DataObject relatedObjectDefinition = _dataDictionary.dataObjects.Find(x => x.objectName.ToUpper() == relatedObjectType.ToUpper());
if (relatedObjectDefinition == null)
throw new Exception("Related data object [" + relatedObjectType + "] not found.");
DataRelationship dataRelationship = parentDataObject.dataRelationships.Find(c => c.relatedObjectName.ToLower() == relatedObjectDefinition.objectName.ToLower());
if (dataRelationship == null)
throw new Exception("Relationship between data object [" + objectType + "] and related data object [" + relatedObjectType + "] not found.");
DataFilter filter = null;
foreach (PropertyMap propertyMap in dataRelationship.propertyMaps)
{
filter = new DataFilter();
string keyFieldValue = Convert.ToString(dataObject.GetPropertyValue(propertyMap.dataPropertyName));
Expression expression = new Expression();
expression.LogicalOperator = LogicalOperator.And;
expression.RelationalOperator = RelationalOperator.EqualTo;
expression.PropertyName = propertyMap.relatedPropertyName;
expression.Values = new Values() { keyFieldValue };
filter.Expressions.Add(expression);
}
dataObjects = Get(relatedObjectType, filter, 0, 0);
}
catch (Exception ex)
{
_logger.ErrorFormat("Error while geting related data objects", ex);
throw new Exception("Error while geting related data objects", ex);
}
return dataObjects;
}
示例8: MergeProperties
/// <summary>
/// Merges static properties of DataObject.
/// </summary>
/// <param name="baseObject">Base DataObject to be merged.</param>
/// <param name="mergingObject">Merging DataObject to be merged into base DataObject.</param>
/// <param name="checkPaths">Consider paths in the merging.</param>
private void MergeProperties(IDataObject baseObject, IDataObject mergingObject, Boolean checkPaths)
{
foreach (PropertyInfo propertyInfo in mergingObject.GetType().GetRuntimeProperties())
{
Boolean includePath = true;
if (this.Paths != null)
{
includePath = !checkPaths;
foreach (String path in this.Paths)
{
if (propertyInfo.Name == path)
{
includePath = true;
}
}
}
if ((propertyInfo.CanWrite) && (!mergingObject.GetProxyState(propertyInfo.Name)) && (includePath))
{
if (IsDataList(propertyInfo.PropertyType))
{
IDataList propertyValue = (IDataList)propertyInfo.GetValue(mergingObject, new Object[] { });
if (propertyValue != null)
{
IDataList dataList = (IDataList)LightHouse.Elite.Core.Builder.Get(propertyValue.GetType());
for (int i = 0; i < propertyValue.Count; i++)
{
if (IsReferenceObject((IDataObject)propertyValue[i]))
{
dataList.Add(GetReferencedObject((IDataObject)propertyValue[i]));
}
else
{
IDataObject referencedObject = GetProxyObject((IDataObject)propertyValue[i]);
dataList.Add(referencedObject);
}
}
propertyInfo.SetValue(baseObject, dataList, new Object[] { });
}
}
else if (IsDataObject(propertyInfo.PropertyType))
{
DataObject propertyValue = (DataObject)propertyInfo.GetValue(mergingObject, new Object[] { });
if (propertyValue != null)
{
if (IsReferenceObject(propertyValue))
{
// If the Object hasn't been saved, it is persisted as such to the database
if (String.IsNullOrEmpty(propertyValue.ID))
{
IDataObject referencedObject = GetProxyObject(propertyValue);
propertyInfo.SetValue(baseObject, referencedObject, new Object[] { });
}
else
{
propertyInfo.SetValue(baseObject, GetReferencedObject(propertyValue), new Object[] { });
}
}
else
{
IDataObject referencedObject = GetProxyObject(propertyValue);
propertyInfo.SetValue(baseObject, referencedObject, new Object[] { });
}
}
else
{
propertyInfo.SetValue(baseObject, null, new Object[] { });
}
}
else
{
propertyInfo.SetValue(baseObject, propertyInfo.GetValue(mergingObject, new Object[] { }), new Object[] { });
}
}
}
}
示例9: GetReferencedObject
/// <summary>
/// Gets reference object from the DataObject.
/// </summary>
/// <param name="cloningObject">Object to be cloned.</param>
/// <returns>Cloned DataObject.</returns>
private IDataObject GetReferencedObject(IDataObject cloningObject)
{
IDataObject referencedObject = default(IDataObject);
if (this.ResolveDataObject != null)
{
referencedObject = ResolveDataObject(cloningObject.GetDataType(), cloningObject.ID);
}
if (referencedObject == null)
{
referencedObject = LightHouse.Elite.Core.Builder.GetDataObject(cloningObject.GetType(), this.ProxyReferences);
referencedObject.ID = cloningObject.ID;
referencedObject.DynamicType = cloningObject.DynamicType;
}
return referencedObject;
}
示例10: GetProxyObject
/// <summary>
/// Gets proxy object from source object.
/// </summary>
/// <param name="sourceObject">Source DataObject.</param>
/// <returns>Proxied DataObject.</returns>
private IDataObject GetProxyObject(IDataObject sourceObject)
{
IDataObject destinationObject = convertedObjectsCache.Get<DataObject>(sourceObject.GetHashCode().ToString());
if (destinationObject != null)
{
if (IsReferenceObject(sourceObject))
{
IDataObject referencedObject = LightHouse.Elite.Core.Builder.GetDataObject(sourceObject.GetType(), false);
referencedObject.ID = sourceObject.ID;
referencedObject.DynamicType = sourceObject.DynamicType;
return referencedObject;
}
}
else
{
destinationObject = LightHouse.Elite.Core.Builder.GetDataObject(sourceObject.GetType(), false);
convertedObjectsCache.Add(sourceObject.GetHashCode().ToString(), destinationObject);
}
MergeDataObject(destinationObject, sourceObject, false);
return destinationObject;
}
示例11: IsReferenceObject
/// <summary>
/// Checks if the DataObject is a reference object or not.
/// </summary>
/// <param name="dataObject">DataObject to bec checked.</param>
/// <returns>Wheter the DataObject is reference or not.</returns>
private static Boolean IsReferenceObject(IDataObject dataObject)
{
if (typeof(IReferenceObject).GetTypeInfo().IsAssignableFrom(dataObject.GetType().GetTypeInfo()))
{
return true;
}
return false;
}
示例12: Equals
/// <summary>
/// 현재 개체가 동일한 형식의 다른 개체와 같은지 여부를 나타냅니다.
/// </summary>
/// <returns>
/// 현재 개체가 <paramref name="other"/> 매개 변수와 같으면 true이고, 그렇지 않으면 false입니다.
/// </returns>
/// <param name="other">이 개체와 비교할 개체입니다.</param>
public virtual bool Equals(IDataObject other) {
return (other != null) &&
(GetType() == other.GetType()) &&
GetHashCode().Equals(other.GetHashCode());
}
示例13: GetRelatedObjects
public override IList<IDataObject> GetRelatedObjects(IDataObject dataObject, string relatedObjectType, int pageSize, int startIndex)
{
string objectType = dataObject.GetType().Name;
IList<IDataObject> dataObjects = null;
if (objectType == typeof(GenericDataObject).Name)
{
objectType = ((GenericDataObject)dataObject).ObjectType;
}
try
{
DataObject parentDataObject = _dataDictionary.dataObjects.Find(x => x.objectName.ToUpper() == objectType.ToUpper());
if (parentDataObject == null)
throw new Exception("Parent data object [" + objectType + "] not found.");
DataObject relatedObjectDefinition = _dataDictionary.dataObjects.Find(x => x.objectName.ToUpper() == relatedObjectType.ToUpper());
if (relatedObjectDefinition == null)
throw new Exception("Related data object [" + relatedObjectType + "] not found.");
DataRelationship dataRelationship = parentDataObject.dataRelationships.Find(c => c.relatedObjectName.ToLower() == relatedObjectDefinition.objectName.ToLower());
if (dataRelationship == null)
throw new Exception("Relationship between data object [" + objectType + "] and related data object [" + relatedObjectType + "] not found.");
string pID = Convert.ToString(dataObject.GetPropertyValue(parentDataObject.keyProperties[0].ToString()));
string url = GenerateReletedUrl(objectType, pID, relatedObjectType, pageSize, startIndex);
string jsonString = GetJsonResponseFrom(url);
DataTable dataTable = GetDataTableFrom(jsonString, objectType);
dataObjects = ToDataObjects(dataTable, objectType);
}
catch (Exception ex)
{
_logger.ErrorFormat("Error while geting related data objects", ex);
throw new Exception("Error while geting related data objects", ex);
}
return dataObjects;
}
示例14:
void IDataObject.UpdateValues(IDataObject dummy)
{
Contract.Requires(dummy != null);
Contract.Requires(dummy.GetType() == this.GetType());
}
示例15: UpdateAvailableDataFormats
// Update and describe all available data formats
private void UpdateAvailableDataFormats(IDataObject dataObject)
{
clipboardInfo.AppendText("Clipboard DataObject Type: ");
clipboardInfo.AppendText(dataObject.GetType().ToString());
clipboardInfo.AppendText("\n\n****************************************************\n\n");
var formats = dataObject.GetFormats();
clipboardInfo.AppendText(
"The following data formats are present in the data object obtained from the clipboard:\n");
if (formats.Length > 0)
{
foreach (var format in formats)
{
bool nativeData;
if (dataObject.GetDataPresent(format, false))
{
nativeData = true;
clipboardInfo.AppendText("\t- " + format + " (native)\n");
}
else
{
nativeData = false;
clipboardInfo.AppendText("\t- " + format + " (autoconvertable)\n");
}
if (nativeData)
{
lbPasteDataFormat.Items.Add(format);
}
else if ((bool) cbAutoConvertibleData.IsChecked)
{
lbPasteDataFormat.Items.Add(format);
}
}
lbPasteDataFormat.SelectedIndex = 0;
}
else
{
clipboardInfo.AppendText("\t- no data formats are present\n");
}
}